package com.waitingresult;

import java.util.HashMap;

/**
 * @Author: WangShuai
 * @CreateTime: 2024-06-24  11:15
 * @Description:
 * @Version: 1.0
 */
public class FindFileName {
    public static void main(String[] args) {
        String[] generateFileName = generateFileName(new String[]{"myfile", "nsha", "myfile", "myfile", "myfile"});
        for (String s : generateFileName) {
            System.err.println(s);
        }

    }

    private static String[] generateFileName(String[] files) {
        String[] result = new String[files.length];

        HashMap<String, Integer> map = new HashMap<>();

        for (int i = 0; i < files.length; i++) {
            String tempName;
            if (map.containsKey(files[i])) {
                map.put(files[i], map.get(files[i]) + 1);
                tempName = files[i] + "(" + map.get(files[i]) + ")";
            } else {
                map.put(files[i], 1);
                tempName = files[i];
            }
            result[i] = tempName;
        }
        return result;
    }
}
